package com.shuai.module.infra.feign.config;

import com.shuai.framework.common.pojo.CommonResult;
import com.shuai.module.infra.client.config.ConfigClient;
import com.shuai.module.infra.domain.po.ConfigDO;
import com.shuai.module.infra.service.ConfigService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.shuai.framework.common.pojo.CommonResult.success;


@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class ConfigApiImplClient implements ConfigClient {

    @Resource
    private ConfigService configService;

    @Override
    public CommonResult<String> getConfigValueByKey(String key) {
        ConfigDO config = configService.getConfigByKey(key);
        return success(config != null ? config.getValue() : null);
    }

}
